import Cookie from 'js-cookie'
import { UserResp } from '../ts/user'

const TokenKey = 'token'
export function getToken(): string {
    return Cookie.get(TokenKey)!
}

export function setToken(token: string) {
    return Cookie.set(TokenKey, token)
}

export function removeToken() {
    return Cookie.remove(TokenKey)
}

const UserKey = 'user'

export function getUser(): UserResp {
    return JSON.parse(Cookie.get(UserKey)!)
}

export function setUser(user: UserResp) {
    return Cookie.set(UserKey, JSON.stringify(user))
}

export function removeUser() {
    return Cookie.remove(UserKey)
}